<html>
<head>
<title>E-mail confirmations<title>
<meta http-equiv="REFRESH" content="2;url=testform.php">
</head>
<body>

<?php

  $connection = mysql_connect( "127.0.0.1", "root", "abc123" );

  if ( !$connection )
  {
    die("Could not connect: " . mysql_error() );    
  } 

  mysql_select_db( "sasystemTables", $connection );

  $query = "SELECT userID, teacherID FROM Assignments;";

  $result = mysql( $query, $connection );

  while ( $row = mysql_fetch_array( $result ) )
  {
    $to = $row['userID'];
    $to2 = $row['teacherID'];

    $message = "Dear '$to',\n" .
               "\n" .
               "This email is to inform you that you have been appointed\n" .
               "\n" .
               "'$fromName' as your mentor at '$schoolTeachingAt' for '$term'\n" .
               "\n" .
               "If you have any questions regarding your appointment feel free to contact\n" .
               "the advisor of this program Stephen Hughes through e-mail at shughes@uni.edu\n" .
               "or by phone at 319-273-2618.\n" .
               "\n" .
               "Sincerely,\n" .
               "Sasystem Support Team";

    $subject = "Testing e-mail";
    $headers = "Testing e-mail";

    mail( $to, $subject, $message, $headers );
    mail( $to2, $subject, $message, $headers );
  }

  mysql_close( $connection );

  echo "<h2>E-mails sent successfully</h2>";
  echo "<span>Please wait while you are directed back to the criteria matching page...</span>";

?>

</body>
</html>
